let baseUrl = 'https://zdcloud.zxkjnc.com/'
export default ({
    url,
    data = {},
    method = 'post',
    loading
}) => {
    if (loading) {
        uni.showLoading({
            title: '请稍后...'
        })
    }
    if (uni.getStorageSync('token')) {
        data.token = uni.getStorageSync('token')
    }
	// data.token = 'o5XVy6whr6IuVYCHJt797vTNfHzo'//全球购（不固定）
    return new Promise(function (reslove, reject) {
        uni.request({
            url: baseUrl + url,
            data,
            method,
            header: {
                'token': uni.getStorageSync('token') || '',
            },
            success(res) {
                if (res.data.code == 1) {
                    reslove(res.data)
                } else if (res.data.code == -1) {
                    uni.removeStorageSync('token')
                    uni.redirectTo({
                        url: '/pages/login/login'
                    })
                } else {
                    reject(res.data)
                    uni.showToast({
                        title: res.data.msg,
                        icon: 'none'
                    })
                }
                if (loading) {
                    uni.hideLoading()
                }
            },
            fail(res) {
                uni.showToast({
                    title: '系统错误',
                    icon: 'none'
                })
                if (loading) {
                    uni.hideLoading()
                }
            }
        })
    })
}